import React from 'react';
import { Form, type FormProps, Button, Space, Card } from 'antd';

interface BaseFormProps extends FormProps {
  children: React.ReactNode;
  onCancel?: () => void;
  submitText?: string;
  cancelText?: string;
  loading?: boolean;
}

// 创建 BaseForm 组件
const BaseFormComponent: React.FC<BaseFormProps> & { Item: typeof Form.Item } = ({
  children,
  onCancel,
  submitText = '提交',
  cancelText = '取消',
  loading = false,
  ...formProps
}) => {
  return (
    <Card>
      <Form
        layout="vertical"
        {...formProps}
      >
        {children}

        <Form.Item style={{ marginBottom: 0, marginTop: 24 }}>
          <Space>
            <Button
              type="primary"
              htmlType="submit"
              loading={loading}
            >
              {submitText}
            </Button>
            {onCancel && (
              <Button onClick={onCancel}>
                {cancelText}
              </Button>
            )}
          </Space>
        </Form.Item>
      </Form>
    </Card>
  );
};

// 添加 Form.Item 到 BaseForm
BaseFormComponent.Item = Form.Item;

export const BaseForm = BaseFormComponent;